<?php
// No direct access
 
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( JPATH_SITE . DS . 'components' . DS . 'com_content' . DS . 'helpers' . DS . 'route.php' );
jimport('joomla.application.component.controller');
 
class NewsletterController extends JController
{

    /**
     * Method to display the view
     *
     * @access    public
     */
    function display()
    {
        parent::display();
    }
 
    function generar()
    {
    	global $mainframe;
    	$params	=& $mainframe->getParams('com_newsletter');
    	$mailer =& JFactory::getMailer();
    	$config =& JFactory::getConfig();
	$sender = array( 
		$config->getValue( 'config.mailfrom' ),
		$config->getValue( 'config.fromname' ) 
	);

	$newsletter = & $this->getModel('Newsletter');

	$newsletter->compilar();

	$mailer->setSender($sender);
	$mailer->addRecipient($params->get( 'direccion_envio' ));
	
	$date = JFactory::getDate()->toFormat('%A, %d de %B de %Y');
	$asunto = $params->get('asunto_newsletter');
	$asunto = str_replace("#fecha", $date, $asunto);
	$mailer->setSubject($asunto);
	$mailer->isHTML(true);
	#$mailer->Encoding = 'utf8';#'base64';
	$mailer->setBody($newsletter->getBody());
	
	$send =& $mailer->Send();

    	$view = & $this->getView('newsletter', 'html');
	$view->setModel($newsletter);
        $view->preview('generado');
    }
 
}
?>